package com.besttone.rabbit.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;

import com.besttone.rabbit.dto.Student;

@Service
public class Producers  implements RabbitTemplate.ConfirmCallback,RabbitTemplate.ReturnCallback {
	Logger logger=LoggerFactory.getLogger(Producers.class);
	@Autowired
    RabbitMessagingTemplate rabbitSendTemplate;

    public void send(Student student) {
        System.out.println("send start.....");

        rabbitSendTemplate.setConfirmCallback(this);
        rabbitSendTemplate.setReturnCallback(this);

        rabbitSendTemplate.convertAndSend("default.topic", "test2.send", student);
    }

	public void confirm(CorrelationData correlationData, boolean ack, String cause) {
		 System.out.println("send confirm....."+ack+cause);
		
	}

	public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
		 System.out.println("send returnedMessage....."+replyCode+replyText);
		
	}
}
